package cn.zyx.order.controller;

import cn.zyx.basic.util.LoginContext;
import cn.zyx.basic.util.PageList;
import cn.zyx.order.domain.PetAcquisitionOrder;
import cn.zyx.order.domain.ProductOrder;
import cn.zyx.order.query.PetAcquisitionOrderQuery;
import cn.zyx.order.query.ProductOrderQuery;
import cn.zyx.order.service.IPetAcquisitionOrderService;
import cn.zyx.user.domain.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/petAcquisitionOrder")
public class PetAcquisitionOrderController {
    /*@Autowired
    private IPetAcquisitionOrderService petAcquisitionOrderService;
    @PostMapping
    public PageList<PetAcquisitionOrder> list(@RequestBody PetAcquisitionOrderQuery query){
        //员工只能查看到自己收购订单
        query.setHandlerId(EmployeeContext.getLoginEployee().getId());
        return  petAcquisitionOrderService.queryPage(query);
    }*/

    @Autowired
    private IPetAcquisitionOrderService petAcquisitionOrderService;

    /**
     * 收购订单后台查询接口
     *   平台管理
     *   店铺员工（店铺管理员  + 员工）
     * @param query
     * @return
     */
    @PostMapping("/admin")
    public PageList<PetAcquisitionOrder> queryAdmin(@RequestBody PetAcquisitionOrderQuery query, HttpServletRequest request){
        try {
            LoginInfo loginInfo = LoginContext.getLoginInfo(request);
            return petAcquisitionOrderService.queryAdmin(query, loginInfo.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 前端用户查询自己收购订单
     * @param query
     * @return
     */
    @PostMapping("/user")
    public PageList<PetAcquisitionOrder> queryUser(@RequestBody PetAcquisitionOrderQuery query, HttpServletRequest request){
        try {
            LoginInfo loginInfo = LoginContext.getLoginInfo(request);
            return petAcquisitionOrderService.queryUser(query, loginInfo.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
